package com.kujie.ai.service;

import com.kujie.ai.utils.StreamUtils;
import io.github.guoshiqiufeng.dify.chat.DifyChat;
import io.github.guoshiqiufeng.dify.chat.dto.request.ChatMessageSendRequest;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

@Service
public class DifyChatService {

    @Resource
    private DifyChat difyChat;

    public Flux<String> streamChat(String apiKey, String userId, String input) {
        ChatMessageSendRequest chatMessageSendRequest = new ChatMessageSendRequest();
        chatMessageSendRequest.setApiKey(apiKey);
        chatMessageSendRequest.setContent(input);
        chatMessageSendRequest.setUserId(userId);

        return StreamUtils.parseWorkflowOutput(difyChat.sendChatMessageStream(chatMessageSendRequest));
    }
}
